package com.agritech.mapper;

import com.agritech.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT id, username, password, email, phone, create_time FROM user WHERE username = #{username}")
    User selectByUsername(@Param("username") String username);

    /**
     * 根据ID查询用户
     */

    User selectById(@Param("id") Long id);

    /**
     * 查询所有用户
     */
    @Select("select * from user")
    List<User> selectAll();

    /**
     * 插入用户
     */
    @Insert("INSERT INTO user (username, password, email, phone, create_time) " +
            "VALUES (#{username}, #{password}, #{email}, #{phone}, #{createTime})")
    int insert(User user);

    /**
     * 更新用户信息
     */
    int update(User user);

    /**
     * 删除用户
     */
    int delete(@Param("id") Long id);
}